<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style type="text/css">
.line{border-bottom:1px solid red;}
</style>
 <script type="text/javascript">
$(function(){
	$("#write_btn").click(function(){
		if(confirm("게시글을 작성하시겠습니까?")){
			location.href="${initParam.root }/board_newsWriteView.do";
		}else{
			return false;
		}
		
	});
	$("#search_btn").click(function(){
		if($("#search").val()=="제목"){
			//alert($("#text").val());
			location.href="${initParam.root}/board_newslist.do?text="+$("#text").val();
		}else if($("#search").val()=="카테고리"){
			alert($("#text").val());
		}
	});
});
</script>

<center>
<table cellpadding="3" width="50%" height="15%">
<tr>
	<th class="line">No</th><th width="40%" class="line">Title</th><th class="line">Writer</th><th class="line">Date</th><th class="line">Count</th>
</tr>
<c:set var="searchTitle" ><font style='background-color:yellow'>${requestScope.text }</font></c:set>
<c:forEach items="${requestScope.lvo.list }" var="lvo">
<tr>
	<td align="center">${lvo.no }</td>
	
	<c:if test="${sessionScope.mvo!=null}">
	<td><a href="${initParam.root }/board_newsview.do?&no=${lvo.no }">
	${fn:replace(lvo.title,requestScope.text,searchTitle) }
	</a></td>
	</c:if>
	
	<c:if test="${sessionScope.mvo==null}">
	<td>${lvo.title }</td>
	</c:if>
	
	<td align="center">${lvo.memberVO.id }</td><td align="center">${lvo.writedate }</td><td align="center">${lvo.count }</td>
</tr>
</c:forEach>
</table>
<c:if test="${sessionScope.mvo!=null}">
	<input type="button" id="write_btn" value="글쓰기">
</c:if>

<c:if test="${requestScope.lvo.pagingBean.previousPageGroup}">
	 <a href="${initParam.root }/board_newslist.do?pageNo=${requestScope.lvo.pagingBean.startPageOfPageGroup-1}">
	 <img src="img/left_arrow_btn.gif">
	 </a>
	 </c:if>
	 &nbsp;&nbsp;
<!-- 	PagingBean 을 이용해서 현재 페이지에 해당되는 페이지그룹의
		   시작페이지~~마지막페이지까지 화면에 보여준다. 
		   이 때 현재 페이지를 제외한 나머지 페이지는 링크를 걸어
		   해당 페이지에 대한 게시물 리스트 조회가 가능하도록 한다.  -->
		
	<c:forEach var="i" begin="${requestScope.lvo.pagingBean.startPageOfPageGroup}"end="${requestScope.lvo.pagingBean.endPageOfPageGroup}">
	 <c:choose>
	 <c:when test="${requestScope.lvo.pagingBean.nowPage!=i}">
	 <a href="${initParam.root }/board_newslist.do?pageNo=${i}&text=${requestScope.text}">${i}</a>
	 </c:when>
	 <c:otherwise>
	${i}
	</c:otherwise>
	</c:choose>
	</c:forEach>	 
	&nbsp;&nbsp;

	
	 <c:if test="${requestScope.lvo.pagingBean.nextPageGroup}">
	 <a href=
	 "${initParam.root }/board_newslist.do?pageNo=${requestScope.lvo.pagingBean.endPageOfPageGroup+1}">
	  <img src="img/right_arrow_btn.gif">
	 </a>
	 </c:if><br><br>
	 <select id="search">
	 <option>---</option>
	 <option id="title">제목</option>
	 <option id="category">카테고리</option>
	 </select>
	 <input type="text" id="text">
	 <input type="button" id="search_btn" value="검색">
<center>
